<template>
  <div class="app-container">
        <el-form
      :model="queryParams"
      ref="queryRef"
      :inline="true"
      v-show="showSearch"
    >
      <el-form-item label="订单号" prop="outTradeNo	">
        <el-input
          v-model="queryParams.outTradeNo	"
          placeholder="请输入订单号	"
          clearable
          style="width: 200px"
        />
      </el-form-item>
       <el-form-item label="微信支付订单号	" prop="tradeNo	">
        <el-input
          v-model="queryParams.tradeNo	"
          placeholder="请输入微信支付订单号	"
          clearable
          style="width: 200px"
        />
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="Search" @click="getList">搜索</el-button>
        <el-button icon="Refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <right-toolbar
        v-model:showSearch="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>
    <!-- 表格数据 -->
    <el-table
      v-loading="loading"
      :data="roleList"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="退款订单号" prop="refundNo" />
      <el-table-column label="商户订单号" prop="outTradeNo" />
      <el-table-column label="用户ID" prop="userId" />
      <el-table-column label="支付金额" prop="totalAmount" />
      <el-table-column label="本次退款金额" prop="refundAmount" />
      <el-table-column label="退款原因" prop="refundReason" />
      <el-table-column label="退款状态" prop="refundStatus" >
        <template #default="{ row }">
          <span>{{ getRefundStatusText(row.refundStatus) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="创建时间" align="center" prop="createTime">
        <template #default="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      v-model:page="queryParams.page"
      v-model:limit="queryParams.size"
      @pagination="getList"
    />

    

  </div>
</template>

<script setup name="Role">
import { listRole} from "@/api/min-app/refund-order";
const { proxy } = getCurrentInstance();

const roleList = ref([]);
const loading = ref(true);
const total = ref(0);
const dateRange = ref([]);
const showSearch = ref(true);

const data = reactive({
  queryParams: {
    page: 1,
    size: 10,
    outTradeNo: '',
    tradeNo: '',
  },
});

const refundStatusMap = {
   0: "退款中",
  1: "退款成功",
  2: "退款失败",
  3: "未退款",
};

const getRefundStatusText = (val) => refundStatusMap[val] || "未知";


const { queryParams, form, rules } = toRefs(data);

/** 查询角色列表 */
function getList() {
  loading.value = true;

 const params = {
    page: queryParams.value.page,
    size: queryParams.value.size,
    tradeNo: queryParams.value.tradeNo || "",
    outTradeNo: queryParams.value.outTradeNo || "",
  };

listRole(params).then(res => {
  roleList.value = res.data.records
  total.value = Number(res.data.total)   // 保证是数字
  loading.value = false
})


}

// 重置搜索
function resetQuery() {
  queryParams.value = { page: 1, size: 10 };
  getList();
}
/** 多选框选中数据 */
function handleSelectionChange(selection) {
  ids.value = selection.map((item) => item.roleId);
  single.value = selection.length != 1;
  multiple.value = !selection.length;
}
getList();
</script>
